package com.uplooking.controller;

import java.util.HashMap;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.uplooking.constant.SysConstants;
import com.uplooking.service.CheckService;
import com.uplooking.service.RepairService;
import com.uplooking.service.ReturnService;

@Controller
public class ReturnController {

	@Autowired
	private ReturnService returnService;

	@RequestMapping(value = "/return/info", method = RequestMethod.GET)
	public String methodReturn1() {
		return "service/return/info";
	}

	@RequestMapping(value = "/return/index", method = RequestMethod.GET)
	public String methodReturn2() {
		return "service/return/index";
	}

	@ResponseBody
	@RequiresPermissions("return!list")
	@RequestMapping(value = "/return/list", method = RequestMethod.GET, produces = { "application/json;charset=utf-8" })
	public String methodReturn3(String rnid, int index, int size, int step) throws Exception {
		return JSONObject.toJSONString(returnService.getReturnList(rnid, index, size, step));
	}

	@ResponseBody
	@RequiresPermissions("return!add")
	@RequestMapping(value = "/return/add", method = RequestMethod.POST, produces = { "application/json;charset=utf-8" })
	public String methodReturn4(String rnrtid, String rndesc) throws Exception {
		return JSONObject.toJSONString(returnService.addReturn(rnrtid, rndesc));
	}

	@ResponseBody
	@RequiresPermissions({ "repair!add", "check!add" })
	@RequestMapping(value = "/repaircheck/add", method = RequestMethod.POST, produces = {
			"application/json;charset=utf-8" })
	public String methodReturn5(String rnrtid, String[] rrproblem, int rrcost, String rrdesc, String[] ckproblem,
			String ckdesc) throws Exception {
		return JSONObject.toJSONString(returnService.addRepairAndCheck(rnrtid, rrproblem, rrcost, rrdesc, ckproblem, ckdesc));
	}

}
